package com.java.sevice.impl;

import com.java.dto.ResultMsg;
import com.java.repository.UserAccountRespository;
import com.java.sevice.ITransferService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
@Slf4j
public class TransferService implements ITransferService {
    @Autowired
    private UserAccountRespository userAccountRespository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultMsg tryTransfer(Long accountId, BigDecimal amount) {
        log.info("bank1-开始转账 accountId:{} amount:{}", accountId, amount);
        //预留资源逻辑
//        int i=1/0;
        return ResultMsg.ok("ok");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultMsg confirmTransfer(Long accountId, BigDecimal amount) {
        log.info("bank1-确认转账 accountId:{} amount:{}", accountId, amount);
        //确认逻辑
        return ResultMsg.ok("ok");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultMsg cancelTransfer(Long accountId, BigDecimal amount) {
        log.info("bank1-取消转账 accountId:{} amount:{}", accountId, amount);
        //回退逻辑
        return ResultMsg.ok("ok");
    }

}